#include "view_time_3.inc"

#include "view_time_3.h"

#include "view_time_0.h"
#include "display_ctrl.h"
#include "platform_assert.h"
#include "lfs_file_manager_auto.h"
#include "rtc.h"
#include "datetime.h"
#include "blecom.h"
#include "battery_ctrl.h"
#include "sport_his.h"
#include "display_ctrl.h"
#include "display_interface_240x240.h"
#include "datetime.h"
#include "heart_rate_interface.h"
#include "font/num_font.h"
#include "font_mngr.h"
#include "view_common.h"
#include "app_trace.h"
#include "weather_ctrl.h"
#include "view_times.h"

#if defined(TIME_18_SKIP) && defined(TIME_3_SKIP)
#else
 void show_time_3_time(void)
{
    disp_draw_user_image_ignore_color(3 + 32 + 6 + 32 + 6, 124, RGB565_COLOR_BLACK, img_time_3_point);
    uint8_t const img_time_3_num_TAB[] = {
        FILE_IMG_4100_time_0_3_81, /* 39 */
        FILE_IMG_4101_time_1_3_81, /* 40 */
        FILE_IMG_4102_time_2_3_81, /* 41 */
        FILE_IMG_4103_time_3_3_81, /* 42 */
        FILE_IMG_4104_time_4_3_81, /* 43 */
        FILE_IMG_4105_time_5_3_81, /* 44 */
        FILE_IMG_4106_time_6_3_81, /* 45 */
        FILE_IMG_4107_time_7_3_81, /* 46 */
        FILE_IMG_4108_time_8_3_81, /* 47 */
        FILE_IMG_4109_time_9_3_81, /* 48 */
    };

    _disp_show_flash_img(DISP_LFS_FILE_INDEX_0, 3, 81, img_time_3_num_TAB[disp_ctrl.com_data.i_temp[3] / 10]);
    _disp_show_flash_img(DISP_LFS_FILE_INDEX_1, 3 + 32 + 6, 81, img_time_3_num_TAB[disp_ctrl.com_data.i_temp[3] % 10]);
    _disp_show_flash_img(DISP_LFS_FILE_INDEX_2, 3 + 32 + 6 + 32 + 6 + 11 + 6, 81, img_time_3_num_TAB[disp_ctrl.com_data.i_temp[4] / 10]);
    _disp_show_flash_img(DISP_LFS_FILE_INDEX_3, 3 + 32 + 6 + 32 + 6 + 11 + 6 + 32 + 6, 81, img_time_3_num_TAB[disp_ctrl.com_data.i_temp[4] % 10]);
}
#endif
#ifdef TIME_3_SKIP
#else
static void show_time_3_icon(void)
{
    disp_draw_user_image_ignore_color(198, 48, RGB565_COLOR_BLACK, img_time_3_steps);
    disp_draw_user_image_ignore_color(200, 189, RGB565_COLOR_BLACK, img_time_3_calorie);
    disp_draw_user_image_ignore_color(197, 120, RGB565_COLOR_BLACK, img_time_3_heart_1);
}

void show_time_3_percent(uint8_t const *base, uint8_t const *full, int percent, int x, int y)
{
    if (percent < 0)
    {
        percent = 0;
    }
    else if (percent > 100)
    {
        percent = 100;
    }
    disp_draw_user_image(x, y, base);
    disp_draw_user_image_percent_circle(x, y, full, percent, 54);
}
static void show_time_3_steps_percent(void)
{
    int percent = disp_ctrl.com_data.i_temp[11] * 100 / system_config_get_target_step();
    show_time_3_percent(img_time_3_steps_base, img_time_3_steps_full, percent, 179, 28);
}
static void show_time_3_calorie_percent(void)
{
    int percent = disp_ctrl.com_data.i_temp[16] * 100 / system_config_get_target_calorie();
    show_time_3_percent(img_time_3_calorie_base, img_time_3_calorie_full, percent, 179, 171);
}
static void show_time_3_heart_rate_percent(void)
{
    int max_heart_rate = 220 - system_config_get_age();
    int min_heart_rate = 40;
    int percent = (disp_ctrl.com_data.i_temp[17] - min_heart_rate) * 100 / (max_heart_rate - min_heart_rate);
    show_time_3_percent(img_time_3_heart_rate_base, img_time_3_heart_rate_full, percent, 179, 100);
}
void view_time_3_display(void)
{
    show_time_0_ble();
    show_time_0_battery(disp_ctrl.com_data.i_temp[7], disp_ctrl.com_data.i_temp[8]);
    show_time_3_date();
    show_time_3_weather();
    show_time_3_time();
    show_time_3_weeks();
    show_time_3_steps_percent();
    show_time_3_calorie_percent();
    show_time_3_heart_rate_percent();
    show_time_3_icon();
}
#endif
